<!DOCTYPE html>
<html>
	<head>
		<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
		<script src="js/qrcode.min.js" type="text/javascript" charset="utf-8"></script>
		<meta charset="utf-8">
		<title></title>
		<script>
			function getPathOfPage(){
				/////////////JS获取项目名//////////////
				//获取当前网址，如：
				var curWwwPath=window.document.location.href;
				
				//获取主机地址之后的目录如：/Tmall/index.jsp
				var pathName=window.document.location.pathname;
				var pos=curWwwPath.indexOf(pathName);
				
				//获取主机地址，如：//localhost:8080
				var localhostPaht=curWwwPath.substring(0,pos);
				
				//获取带"/"的项目名，如：/Tmall
				var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); 
				
				// "http://localhost:8080/QM/loginci.html?d=1638322099989" -> projectName: "/QM"
				
				/////////////////////////////////////
				return localhostPaht + projectName;
			}
		
			$(function() {
				$("#upload").click(function() {
					console.log($("#my_file").val()); //$('#uploadForm')[0]
					$myfile = $("#my_file");
					formData = new FormData();
					formData.append("photo", $myfile[0].files[0]);
					formData.append("message", "123456");
					formData.append("666", 'i love ajax');
					formData.append("666", 'i love ajax');

					$.ajax({
						type: "post",
						url: getPathOfPage()+"/JpgUploadFaceTestServlet",
						data:formData,
						type: "POST",

						contentType: "multipart/form-data",
						async: false, //异步
						processData: false, //很重要，告诉jquery不要对form进行处理
						contentType: false, //很重要，指定为false才能形成正确的Content-Type
						success: function(message) {
							alert("完成");
							$("#my_message").text(message);
						},
					});
				})
			})
		</script>
	</head>
	<body>

		<div>
			<label>input</label>
			<input id="my_file" type="file" />
			<button id="upload">上传</button>
		</div>
		<p id="my_message">现在没有信息</p>
		
		<div id="qrcode"></div>
		<script type="text/javascript">
		new QRCode(document.getElementById("qrcode"),{
			text:"666",
			width:100,
			height:100
		});  // 设置要生成二维码的链接
		</script>
	</body>
</html>
